

package com.hazelcast.test.starter.constructor;

import com.hazelcast.test.starter.HazelcastStarterConstructor;

import java.lang.reflect.Constructor;

import static com.hazelcast.test.starter.ReflectionUtils.getFieldValueReflectively;

@HazelcastStarterConstructor(classNames = {"com.hazelcast.version.MemberVersion"})
public class MemberVersionConstructor extends AbstractStarterObjectConstructor {

    public MemberVersionConstructor(Class<?> targetClass) {
        super(targetClass);
    }

    @Override
    Object createNew0(Object delegate) throws Exception {
        // obtain reference to constructor MemberVersion(int major, int minor, int patch)
        Constructor<?> constructor = targetClass.getDeclaredConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE);

        Byte major = (Byte) getFieldValueReflectively(delegate, "major");
        Byte minor = (Byte) getFieldValueReflectively(delegate, "minor");
        Byte patch = (Byte) getFieldValueReflectively(delegate, "patch");
        Object[] args = new Object[]{major, minor, patch};

        return constructor.newInstance(args);
    }
}
